<?php

namespace App\Http\Controllers;

use App\Models\Reply;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\ReplyRequest;
use Illuminate\Support\Facades\Auth;

class RepliesController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth', ['except' => ['index', 'show']]);
    }
	public function store(ReplyRequest $request)
	{
	    $topic_id = $request->topic_id;
	    $request = $request->all();
	    $request['user_id'] = Auth::id();
	    $request['topic_id'] = $topic_id;
		$reply = Reply::create($request);
		return redirect()->route('topics.show', $topic_id)->with('message', 'Created successfully.');
	}
	public function destroy(Reply $reply)
	{
		$this->authorize('destroy', $reply);
		$reply->delete();

		return redirect()->to($reply->topic->link())->with('message', 'Deleted successfully.');
	}
}